package com.kaifamiao.high.thread;

import java.time.LocalTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author lucien-ma
 * @date 2021/10/9
 * @apiNote
 */
public class Demo06 {
    public static void main(String[] args) {
        // 创建一个固定线程数量的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 10; i++) {
            int number = i;
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("当前时间：" + LocalTime.now() +
                            ", 线程：" + Thread.currentThread().getName() +
                            ", 序号：" + number);
                    try {
                        Thread.currentThread().sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        // 执行完任务后关闭
        executorService.shutdown();
    }
}
